package com.dgh.school.service.impl;

import com.dgh.school.bean.Affair;

import com.dgh.school.common.R;
import com.dgh.school.mapper.AffairMapper;
import com.dgh.school.service.AffairService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AffairServiceImpl implements AffairService {

    @Autowired
    private AffairMapper affairMapper;

    @Override
    public List<Affair> selectAll() {

        List<Affair> affairs = affairMapper.selectAll();
        return affairs;
    }

    @Override
    public R selectByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        // 查询全部数据
        List<Affair> affairs = affairMapper.selectAll();
        // 借助分页助手，获得分页信息
        PageInfo<Affair> pageInfo = new PageInfo<>(affairs);

        return R.ok().setDate("pageInfo", pageInfo);
    }

    @Override
    public void deleteAffair(int id) throws Exception {
        affairMapper.deleteAffair(id);
    }



    @Override
    public void updateData(Affair affair) throws Exception{
        affairMapper.updateData(affair);
    }
}
